from ooxcb.eventsys import EventDispatcher

class Object(EventDispatcher):
    def __init__(self):
        EventDispatcher.__init__(self)

class Rect(object):
    __slots__ = ['x', 'y', 'width', 'height']
    
    def __init__(self, x=0, y=0, width=100, height=100):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
    
    def copy(self):
        return Rect(self.x, self.y, self.width, self.height)
    
    def __str__(self):
        return "<Rect %s %s %s %s>" % (self.x, self.y, self.width, self.height)
    
    def to_dict(self):
        return {'x': self.x, 'y': self.y,
                'width': self.width, 'height':self.height}
    
    @classmethod
    def from_object(cls, struct):
        return cls(struct.x, struct.y, struct.width, struct.height)
    
    @classmethod
    def from_dict(cls, _dict):
        return cls(_dict['x'], _dict['y'], _dict['width'], _dict['height'])
